package com.gisocn.onemap.ui.fragment;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import com.gisocn.onemap.base.BaseFragment;
import com.gisocn.onemap.base.Constant;
import com.gisocn.onemap.event.MessageEvent;
import com.gisocn.onemap.interfaces.DownLoadListener;
import com.gisocn.onemap.interfaces.OnItemClickListener;
import com.gisocn.onemap.model.AppConfig;
import com.gisocn.onemap.model.Download;
import com.gisocn.onemap.model.LoadResponseHead;
import com.gisocn.onemap.model.TreePoint;
import com.gisocn.onemap.presenter.OfflineDownloadPresenter;
import com.gisocn.onemap.sgzx.R;
import com.gisocn.onemap.ui.activity.MainActivity;
import com.gisocn.onemap.ui.adapter.TreeDownloadAdapter;
import com.gisocn.onemap.utils.AppUtils;
import com.gisocn.onemap.utils.L;
import com.gisocn.onemap.utils.tree.TreeUtils;
import com.gisocn.onemap.view.OfflineDownloadView;
import com.gisocn.onemap.widget.MyProgress;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.greenrobot.eventbus.EventBus;

/* loaded from: classes2.dex */
public class NewOfflineDownloadFragment extends BaseFragment<OfflineDownloadPresenter> implements OfflineDownloadView {
    private TreeDownloadAdapter adapter;
    private AppConfig appConfig;
    private ArrayList<Download.NewItem> groupList;
    @BindView(R.id.lv_tree)
    ListView lvTree;
    private ArrayList<String> positionList;
    private OfflineDownloadPresenter presenter;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    private Unbinder unbinder;
    private ArrayList<TreePoint> pointList = new ArrayList<>();
    private HashMap<String, TreePoint> pointMap = new HashMap<>();
    private ArrayList<Download.NewItem> xmlList = new ArrayList<>();
    private Map<String, Download.NewItem> dataMaps = new LinkedHashMap();
    private boolean isShowProgress = false;
    private ArrayList<String> downloadNameList = new ArrayList<>();
    OnItemClickListener onGroupItemCheckListener = new OnItemClickListener() { // from class: com.gisocn.onemap.ui.fragment.NewOfflineDownloadFragment.2
        @Override // com.gisocn.onemap.interfaces.OnItemClickListener
        public void onItemClick(View view, int i, int i2) {
        }

        @Override // com.gisocn.onemap.interfaces.OnItemClickListener
        public void onItemClick(View view, int i) {
            NewOfflineDownloadFragment.this.btnAllClick(view, i);
        }
    };
    OnItemClickListener onChildItemCheckListener = new OnItemClickListener() { // from class: com.gisocn.onemap.ui.fragment.NewOfflineDownloadFragment.3
        @Override // com.gisocn.onemap.interfaces.OnItemClickListener
        public void onItemClick(View view, int i, int i2) {
        }

        @Override // com.gisocn.onemap.interfaces.OnItemClickListener
        public void onItemClick(View view, int i) {
            int convertPostion = NewOfflineDownloadFragment.this.adapter.convertPostion(i);
            NewOfflineDownloadFragment.this.childItemClick(convertPostion, i);
            NewOfflineDownloadFragment.this.downloadNameList.add(((TreePoint) NewOfflineDownloadFragment.this.pointList.get(convertPostion)).getNNAME());
        }
    };
    Handler handler = new Handler() { // from class: com.gisocn.onemap.ui.fragment.NewOfflineDownloadFragment.7
        @Override // android.os.Handler
        public void handleMessage(Message message) {
            String[] split;
            String[] split2;
            String[] split3;
            super.handleMessage(message);
            int i = message.what;
            if (i == 1) {
                NewOfflineDownloadFragment.this.dismissProgressDialog();
                NewOfflineDownloadFragment.this.initView();
                Log.e("groupList.size()", NewOfflineDownloadFragment.this.groupList.size() + "");
                ((MainActivity) NewOfflineDownloadFragment.this.getActivity()).setUpdateCounts(NewOfflineDownloadFragment.this.presenter.getUpdateCounts(NewOfflineDownloadFragment.this.pointList));
                return;
            }
            if (i == 2) {
                String str = "0";
                String str2 = message.obj + "";
                if (str2 == null || str2.length() <= 0 || (split = str2.split(",")) == null || split.length <= 0) {
                    return;
                }
                int parseInt = Integer.parseInt(split[0]);
                int parseInt2 = Integer.parseInt(split[1]);
                if (NewOfflineDownloadFragment.this.downloadNameList != null && NewOfflineDownloadFragment.this.downloadNameList.size() > 0) {
                    for (int i2 = 0; i2 < NewOfflineDownloadFragment.this.downloadNameList.size(); i2++) {
                        if (((TreePoint) NewOfflineDownloadFragment.this.pointList.get(parseInt)).getNNAME().equals(NewOfflineDownloadFragment.this.downloadNameList.get(i2))) {
                            str = "ok";
                        }
                    }
                }
                if ("ok".equals(str)) {
                    if (message.arg1 == 100) {
                        ((MainActivity) NewOfflineDownloadFragment.this.getActivity()).setUpdateCounts(NewOfflineDownloadFragment.this.presenter.getUpdateCounts(NewOfflineDownloadFragment.this.pointList));
                        EventBus.getDefault().post(new MessageEvent(Constant.MESSAGE_EVENT_UPDATA_LAYER_DATA));
                        NewOfflineDownloadFragment.this.uiHandler.sendEmptyMessage(1);
                    }
                    NewOfflineDownloadFragment.this.notifyDataSetChangedSingle(parseInt2);
                }
            } else if (i == 3) {
                String str3 = message.obj + "";
                if (str3 == null || str3.length() <= 0 || (split2 = str3.split(",")) == null || split2.length <= 0) {
                    return;
                }
                int parseInt3 = Integer.parseInt(split2[0]);
                int parseInt4 = Integer.parseInt(split2[1]);
                ((TreePoint) NewOfflineDownloadFragment.this.pointList.get(parseInt3)).setVersionDesc("已是最新版本");
                NewOfflineDownloadFragment.this.notifyDataSetChangedSingle(parseInt4);
                NewOfflineDownloadFragment.this.checkGroupOrChild(parseInt3);
                NewOfflineDownloadFragment.this.uiHandler.sendEmptyMessage(1);
            } else {
                if (i != 4) {
                    return;
                }
                NewOfflineDownloadFragment.this.dismissProgressDialog();
                NewOfflineDownloadFragment.this.showToast("下载失败");
                String str4 = message.obj + "";
                if (str4 == null || str4.length() <= 0 || (split3 = str4.split(",")) == null || split3.length <= 0) {
                    return;
                }
                Integer.parseInt(split3[0]);
                NewOfflineDownloadFragment.this.notifyDataSetChangedSingle(Integer.parseInt(split3[1]));
            }
        }
    };
    Handler uiHandler = new Handler() { // from class: com.gisocn.onemap.ui.fragment.NewOfflineDownloadFragment.8
        @Override // android.os.Handler
        public void handleMessage(Message message) {
            if (message.what == 1 && NewOfflineDownloadFragment.this.adapter != null) {
                NewOfflineDownloadFragment.this.adapter.notifyDataSetChanged();
            }
        }
    };

    @Override // com.gisocn.onemap.view.OfflineDownloadView
    public void getDownLoadSuccess(String str, int i) {
    }

    @Override // com.gisocn.onemap.base.BaseFragment
    protected void onInvisible() {
    }

    @Override // com.gisocn.onemap.base.BaseFragment, androidx.fragment.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_offline_download, viewGroup, false);
        this.unbinder = ButterKnife.bind(this, inflate);
        this.tvTitle.setText(R.string.offline_download);
        this.tvRight.setVisibility(8);
        initData();
        this.isShowProgress = true;
        return inflate;
    }

    @Override // com.gisocn.onemap.base.BaseFragment
    protected void initData() {
        getDataFromConfig();
    }

    void initView() {
        dismissProgressDialog();
        Log.e("init", "init----------下载测试----------");
        this.positionList = new ArrayList<>();
        TreeDownloadAdapter treeDownloadAdapter = new TreeDownloadAdapter(getActivity(), this.pointList, this.pointMap);
        this.adapter = treeDownloadAdapter;
        this.lvTree.setAdapter((ListAdapter) treeDownloadAdapter);
        this.adapter.setOnGroupItemClickListener(this.onGroupItemCheckListener);
        this.adapter.setOnChildItemClickListener(this.onChildItemCheckListener);
        this.lvTree.setOnItemClickListener(new AdapterView.OnItemClickListener() { // from class: com.gisocn.onemap.ui.fragment.NewOfflineDownloadFragment.1
            @Override // android.widget.AdapterView.OnItemClickListener
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                NewOfflineDownloadFragment.this.adapter.onItemClick(i);
            }
        });
    }

    public void getDataFromConfig() {
        ArrayList<TreePoint> arrayList = this.pointList;
        if (arrayList != null && arrayList.size() > 0) {
            this.pointList.clear();
        }
        AppConfig appConfig = ((MainActivity) getActivity()).getAppConfig();
        this.appConfig = appConfig;
        ArrayList<Download.NewItem> items = appConfig.getDownload().getItems();
        if (items != null && items.size() > 0) {
            for (int i = 0; i < items.size(); i++) {
                if (items.get(i).getItems() != null && items.get(i).getItems().size() > 0) {
                    items.get(i).getItems().clear();
                }
            }
        }
        this.presenter = createPresenter();
        if (this.appConfig.getDownload().getItems() == null || this.appConfig.getDownload().getItems().size() <= 0) {
            return;
        }
        this.xmlList.clear();
        this.dataMaps.clear();
        ArrayList<Download.NewItem> arrayList2 = this.groupList;
        if (arrayList2 != null && arrayList2.size() > 0) {
            this.groupList.clear();
        } else {
            this.groupList = new ArrayList<>();
        }
        Iterator<Download.NewItem> it = this.appConfig.getDownload().getItems().iterator();
        while (it.hasNext()) {
            Download.NewItem next = it.next();
            if (next.getVersionDesc() == null || next.getVersionDesc().length() <= 0) {
                next.setVersionDesc("");
            }
            String[] split = next.getcData().trim().split("/");
            if (split != null && split.length > 0) {
                String str = split[split.length - 1];
                if ("0".equals(next.getType())) {
                    this.dataMaps.put(next.getGroup(), next);
                } else if (!this.dataMaps.containsKey(str)) {
                    L.e("文件名:" + str);
                    if (!this.dataMaps.containsKey(str)) {
                        if (next.getType().equals("shapefile")) {
                            next = checkLocalFile(Constant.SAVE_PATH_SHP, next, str);
                        } else if (next.getType().equals("tpk")) {
                            next = checkLocalFile(Constant.SAVE_PATH_TPK, next, str);
                        }
                        this.dataMaps.put(str, next);
                    } else {
                        this.dataMaps.put(next.getGroup(), next);
                    }
                }
            }
        }
        L.e("本地文件长度:" + this.presenter.getLocalPathFile(Constant.SAVE_PATH_TPK, null).size());
        ArrayList arrayList3 = new ArrayList();
        arrayList3.addAll(this.presenter.getLocalPathFile(Constant.SAVE_PATH_TPK, null));
        Iterator it2 = arrayList3.iterator();
        while (it2.hasNext()) {
            File file = (File) it2.next();
            if (this.dataMaps.containsKey(file.getName())) {
                this.dataMaps.get(file.getName()).setLastModifiedTime(Long.valueOf(file.lastModified()));
            }
        }
        this.xmlList.addAll(this.dataMaps.values());
        ArrayList<Download.NewItem> arrayList4 = this.xmlList;
        if (arrayList4 != null && arrayList4.size() > 0) {
            for (int i2 = 0; i2 < this.xmlList.size(); i2++) {
                if (this.xmlList.get(i2).getType() != null && "0".equals(this.xmlList.get(i2).getType())) {
                    this.groupList.add(this.xmlList.get(i2));
                }
            }
            ArrayList<Download.NewItem> arrayList5 = this.groupList;
            if (arrayList5 != null && arrayList5.size() > 0) {
                for (int i3 = 0; i3 < this.groupList.size(); i3++) {
                    for (int i4 = 0; i4 < this.xmlList.size(); i4++) {
                        if (this.xmlList.get(i4).getType() != null && !"0".equals(this.xmlList.get(i4).getType()) && this.xmlList.get(i4).getGroup().equals(this.groupList.get(i3).getGroup())) {
                            this.groupList.get(i3).getItems().add(this.xmlList.get(i4));
                        }
                    }
                }
            }
        }
        setNoLoadNumber();
        getDataForTree();
        if (this.isShowProgress) {
            showProgressDialog();
        }
        if (ActivityCompat.checkSelfPermission(getActivity(), "android.permission.WRITE_EXTERNAL_STORAGE") == 0) {
            new Thread(new Runnable() { // from class: com.gisocn.onemap.ui.fragment.NewOfflineDownloadFragment.4
                @Override // java.lang.Runnable
                public void run() {
                    NewOfflineDownloadFragment.this.presenter.getDownLoadInfo(((Download.NewItem) NewOfflineDownloadFragment.this.xmlList.get(0)).getcData().trim(), 0);
                }
            }).start();
        } else {
            showToast("请设置文件读写权限");
        }
    }

    public Download.NewItem checkLocalFile(String str, Download.NewItem newItem, String str2) {
        File file = new File(str);
        if (file.exists()) {
            File[] listFiles = file.listFiles();
            if (listFiles == null) {
                newItem.setVersionDesc("未下载");
            } else if (listFiles.length > 0) {
                for (int i = 0; i < listFiles.length; i++) {
                    if (listFiles[i].getName().contains(".temp")) {
                        if (listFiles.length == 1 && str2.equals(listFiles[i].getName().substring(0, listFiles[i].getName().lastIndexOf(".")))) {
                            newItem.setVersionDesc("待更新");
                            newItem.setLastModifiedTime(Long.valueOf(file.lastModified()));
                        } else {
                            newItem.setVersionDesc("未下载");
                        }
                    } else {
                        newItem.setVersionDesc("未下载");
                    }
                }
            } else {
                newItem.setVersionDesc("未下载");
            }
        } else {
            newItem.setVersionDesc("未下载");
        }
        return newItem;
    }

    public void setNoLoadNumber() {
        int countRes;
        ArrayList<Download.NewItem> arrayList = this.groupList;
        if (arrayList == null || arrayList.size() <= 0) {
            return;
        }
        for (int i = 0; i < this.groupList.size(); i++) {
            if (this.groupList.get(i).getItems() != null && this.groupList.get(i).getItems().size() > 0) {
                if (this.groupList.get(i).getItems().size() > 0) {
                    countRes = 0;
                    for (int i2 = 0; i2 < this.groupList.get(i).getItems().size(); i2++) {
                        countRes = this.presenter.getCountRes(this.groupList.get(i).getItems().get(i2).getVersionDesc(), countRes);
                    }
                } else {
                    countRes = 0;
                }
            } else {
                countRes = this.presenter.getCountRes(this.groupList.get(i).getVersionDesc(), 0);
            }
            this.groupList.get(i).setNotLoadNumber(countRes + "");
        }
    }

    public void getDataForTree() {
        int i = 2000;
        int i2 = 0;
        for (int i3 = 0; i3 < this.groupList.size(); i3++) {
            i++;
            if (this.groupList.get(i3).getType() != null && "0".equals(this.groupList.get(i3).getType())) {
                TreePoint treePoint = new TreePoint("" + i, this.groupList.get(i3).getName(), "0", "0", i3);
                treePoint.setNotLoadNumber(this.groupList.get(i3).getNotLoadNumber());
                this.pointList.add(treePoint);
            }
            ArrayList<Download.NewItem> items = this.groupList.get(i3).getItems();
            if (items != null && items.size() > 0) {
                for (int i4 = 0; i4 < items.size(); i4++) {
                    if (i4 == 0) {
                        i2 = i;
                    }
                    i++;
                    TreePoint treePoint2 = new TreePoint("" + i, items.get(i4).getName(), "" + i2, "1", i4);
                    treePoint2.setGroup(items.get(i4).getGroup());
                    treePoint2.setType(items.get(i4).getType());
                    treePoint2.setLabel(items.get(i4).getLabel());
                    treePoint2.setSize(items.get(i4).getSize());
                    treePoint2.setVersion(items.get(i4).getVersion());
                    treePoint2.setcData(items.get(i4).getcData());
                    treePoint2.setVersionDesc(items.get(i4).getVersionDesc());
                    treePoint2.setCurrentLength(items.get(i4).getCurrentLength());
                    treePoint2.setLastModifiedTime(items.get(i4).getLastModifiedTime());
                    treePoint2.setNotLoadNumber(items.get(i4).getNotLoadNumber());
                    this.pointList.add(treePoint2);
                }
            }
        }
        Collections.shuffle(this.pointList);
        updateData();
    }

    private void updateData() {
        Iterator<TreePoint> it = this.pointList.iterator();
        while (it.hasNext()) {
            TreePoint next = it.next();
            this.pointMap.put(next.getID(), next);
        }
        Collections.sort(this.pointList, new Comparator<TreePoint>() { // from class: com.gisocn.onemap.ui.fragment.NewOfflineDownloadFragment.5
            @Override // java.util.Comparator
            public int compare(TreePoint treePoint, TreePoint treePoint2) {
                int level = TreeUtils.getLevel(treePoint, NewOfflineDownloadFragment.this.pointMap);
                int level2 = TreeUtils.getLevel(treePoint2, NewOfflineDownloadFragment.this.pointMap);
                if (level == level2) {
                    if (treePoint.getPARENTID().equals(treePoint2.getPARENTID())) {
                        return treePoint.getDISPLAY_ORDER() > treePoint2.getDISPLAY_ORDER() ? 1 : -1;
                    }
                    return compare(TreeUtils.getTreePoint(treePoint.getPARENTID(), NewOfflineDownloadFragment.this.pointMap), TreeUtils.getTreePoint(treePoint2.getPARENTID(), NewOfflineDownloadFragment.this.pointMap));
                } else if (level > level2) {
                    if (treePoint.getPARENTID().equals(treePoint2.getID())) {
                        return 1;
                    }
                    return compare(TreeUtils.getTreePoint(treePoint.getPARENTID(), NewOfflineDownloadFragment.this.pointMap), treePoint2);
                } else if (treePoint2.getPARENTID().equals(treePoint.getID())) {
                    return -1;
                } else {
                    return compare(treePoint, TreeUtils.getTreePoint(treePoint2.getPARENTID(), NewOfflineDownloadFragment.this.pointMap));
                }
            }
        });
        TreeDownloadAdapter treeDownloadAdapter = this.adapter;
        if (treeDownloadAdapter != null) {
            treeDownloadAdapter.notifyDataSetChanged();
        }
    }

    public void btnAllClick(View view, int i) {
        if ("下载全部".equals(((TextView) view).getText().toString().trim())) {
            TreePoint treePoint = (TreePoint) this.adapter.getItem(i);
            if (!treePoint.isExpand()) {
                treePoint.setExpand(true);
            }
            this.adapter.notifyDataSetChanged();
            if (treePoint != null) {
                if ("0".equals(treePoint.getNotLoadNumber())) {
                    showToast("该科室下所有文件均已下载到本地！");
                    return;
                }
                for (int convertPostion = this.adapter.convertPostion(i) + 1; convertPostion < this.pointList.size(); convertPostion++) {
                    i++;
                    if (treePoint.getID().equals(this.pointList.get(convertPostion).getPARENTID()) && !checkFileIsExist(this.pointList.get(convertPostion))) {
                        childItemClick(convertPostion, i);
                    }
                }
            }
        }
    }

    public void childItemClick(final int i, final int i2) {
        Log.e("onItemClick", "onItemClick" + this.pointList.get(i).getcData());
        if (this.positionList.contains(Integer.valueOf(i))) {
            Message message = new Message();
            message.what = 2;
            message.arg1 = isNull(this.pointList.get(i2).getCurrentLength()) ? 0 : Integer.parseInt(this.pointList.get(i2).getCurrentLength());
            message.obj = i + "," + i2;
            this.handler.sendMessage(message);
            return;
        }
        ArrayList<String> arrayList = this.positionList;
        arrayList.add(i + "");
        Message message2 = new Message();
        int lengthCurrent = getLengthCurrent(this.pointList.get(i2));
        L.e("开始进度currentLength" + lengthCurrent);
        message2.what = 2;
        message2.obj = i + "," + i2;
        message2.arg1 = lengthCurrent;
        this.handler.sendMessage(message2);
        this.presenter.getDownLoading(this.pointList.get(i).getcData().trim(), new DownLoadListener() { // from class: com.gisocn.onemap.ui.fragment.NewOfflineDownloadFragment.6
            @Override // com.gisocn.onemap.interfaces.DownLoadListener
            public void onStart() {
                L.e("onStart____________________");
            }

            @Override // com.gisocn.onemap.interfaces.DownLoadListener
            public void onProgress(int i3) {
                NewOfflineDownloadFragment.this.dismissProgressDialog();
                ((TreePoint) NewOfflineDownloadFragment.this.pointList.get(i2)).setCurrentLength("" + i3);
                if (i3 == 100) {
                    ((TreePoint) NewOfflineDownloadFragment.this.pointList.get(i)).setVersionDesc("已是最新版本");
                }
                Message message3 = new Message();
                message3.what = 2;
                message3.arg1 = i3;
                message3.obj = i + "," + i2;
                NewOfflineDownloadFragment.this.handler.sendMessage(message3);
            }

            @Override // com.gisocn.onemap.interfaces.DownLoadListener
            public void onFinish(String str) {
                Message message3 = new Message();
                message3.what = 3;
                message3.obj = i + "," + i2;
                NewOfflineDownloadFragment.this.handler.sendMessage(message3);
            }

            @Override // com.gisocn.onemap.interfaces.DownLoadListener
            public void onFailure() {
                NewOfflineDownloadFragment.this.handler.sendEmptyMessage(4);
            }
        });
    }

    public void notifyDataSetChangedSingle(int i) {
        int firstVisiblePosition = i - this.lvTree.getFirstVisiblePosition();
        int childCount = this.lvTree.getChildCount();
        if (firstVisiblePosition < 0 || firstVisiblePosition >= childCount) {
            return;
        }
        View childAt = this.lvTree.getChildAt(firstVisiblePosition);
        TextView textView = (TextView) childAt.findViewById(R.id.tv_title);
        textView.getText().toString().trim();
        Log.e("fangfang", "点击第：" + firstVisiblePosition + " 项；\n" + textView.getText().toString());
        MyProgress myProgress = (MyProgress) childAt.findViewById(R.id.progress);
        String currentLength = this.pointList.get(i).getCurrentLength();
        if (currentLength != null && !TextUtils.isEmpty(currentLength)) {
            myProgress.setProgress(Integer.parseInt(currentLength));
        }
        myProgress.setVisibility(0);
        TextView textView2 = (TextView) childAt.findViewById(R.id.btn_offline_download);
        textView2.setVisibility(4);
        TextView textView3 = (TextView) childAt.findViewById(R.id.tv_offline_download_status);
        textView3.setText("下载中...");
        textView3.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorBlue));
        if (myProgress.getProgress() == 100) {
            textView3.setText("已是最新版本");
            textView3.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorBlack));
            textView2.setText("已完成");
            textView2.setEnabled(false);
            textView2.setBackgroundResource(R.drawable.bg_black_radius5_storck);
            textView2.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorBgGray));
            textView2.setVisibility(0);
            myProgress.setVisibility(4);
        }
    }

    public int getLengthCurrent(TreePoint treePoint) {
        String str;
        if (treePoint == null || treePoint.getcData() == null) {
            return 0;
        }
        String trim = treePoint.getcData().trim();
        L.e("xmlList.get(position).getCurrentLength" + treePoint.getCurrentLength());
        L.e("xmlList.get(position).getCurrentLength" + treePoint.getSize());
        String str2 = trim.split("/")[trim.split("/").length + (-1)] + ".temp";
        L.e("xmlList.get(position).getCurrentLength" + str2);
        if (str2.contains(".tpk")) {
            str = Constant.SAVE_PATH_TPK + str2;
        } else {
            str = Constant.SAVE_PATH_SHP + str2;
        }
        File file = new File(str);
        if (file.exists()) {
            L.e("存在临时文件大小" + file.length() + "---" + Float.parseFloat(treePoint.getSize()));
            int length = (int) ((((float) file.length()) / Float.parseFloat(treePoint.getSize())) * 100.0f);
            StringBuilder sb = new StringBuilder();
            sb.append("currentLength===========");
            sb.append(((float) file.length()) / Float.parseFloat(treePoint.getSize()));
            L.e(sb.toString());
            return length;
        }
        return 0;
    }

    public boolean checkFileIsExist(TreePoint treePoint) {
        String str;
        String trim = treePoint.getcData().trim();
        if (trim != null && trim.length() > 0) {
            String str2 = trim.split("/")[trim.split("/").length - 1];
            if (str2.contains(".tpk")) {
                str = Constant.SAVE_PATH_TPK + str2;
            } else {
                str = Constant.SAVE_PATH_SHP + str2;
            }
            if (new File(str).exists()) {
                return true;
            }
        }
        return false;
    }

    @Override // androidx.fragment.app.Fragment
    public void onStop() {
        super.onStop();
        dismissProgressDialog();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.gisocn.onemap.base.BaseFragment
    public OfflineDownloadPresenter createPresenter() {
        return new OfflineDownloadPresenter(this, getActivity());
    }

    @Override // com.gisocn.onemap.base.BaseFragment, androidx.fragment.app.Fragment
    public void onDestroyView() {
        super.onDestroyView();
        this.unbinder.unbind();
        OfflineDownloadPresenter offlineDownloadPresenter = this.presenter;
        if (offlineDownloadPresenter != null) {
            offlineDownloadPresenter.closeDownloading();
        }
        this.handler.removeCallbacksAndMessages(null);
    }

    @OnClick({R.id.tv_close, R.id.tv_right})
    public void onViewClicked(View view) {
        if (view.getId() != R.id.tv_close) {
            return;
        }
        getActivity().findViewById(R.id.viewPager).setVisibility(8);
    }

    public void checkGroupOrChild(int i) {
        if ("0".equals(this.pointList.get(i).getISLEAF())) {
            this.pointList.get(i).setNotLoadNumber(AppUtils.unReadNumber(this.pointList.get(i).getNotLoadNumber()) + "");
            return;
        }
        String parentid = this.pointList.get(i).getPARENTID();
        for (int i2 = 0; i2 < this.pointList.size(); i2++) {
            if ("0".equals(this.pointList.get(i2).getISLEAF()) && parentid.equals(this.pointList.get(i2).getID())) {
                this.pointList.get(i2).setNotLoadNumber(AppUtils.unReadNumber(this.pointList.get(i2).getNotLoadNumber()) + "");
            }
        }
    }

    @Override // com.gisocn.onemap.view.OfflineDownloadView
    public void getDownLoadInfoSuccess(LoadResponseHead loadResponseHead, int i) {
        ArrayList<TreePoint> arrayList = this.pointList;
        if (arrayList == null || arrayList.size() <= 0) {
            return;
        }
        if (this.pointList.get(i).getcData() != null) {
            String[] split = this.pointList.get(i).getcData().trim().split("/");
            String str = split[split.length - 1];
            if (!isNull(loadResponseHead.getLast_modified())) {
                this.dataMaps.get(str).setVersion(String.valueOf(new Date(loadResponseHead.getLast_modified()).getTime()));
            }
            if (!isNull(loadResponseHead.getContent_length())) {
                String content_length = loadResponseHead.getContent_length();
                Map<String, Download.NewItem> map = this.dataMaps;
                if (map != null && map.get(str) != null) {
                    this.dataMaps.get(str).setSize(content_length);
                }
            }
        }
        int i2 = i + 1;
        if (i2 <= this.pointList.size() - 1) {
            if (this.pointList.get(i2).getcData() != null) {
                this.presenter.getDownLoadInfo(this.pointList.get(i2).getcData().trim(), i2);
                return;
            }
            int i3 = i2 + 1;
            this.presenter.getDownLoadInfo(this.pointList.get(i3).getcData().trim(), i3);
            return;
        }
        Iterator<TreePoint> it = this.pointList.iterator();
        while (it.hasNext()) {
            TreePoint next = it.next();
            if (next.getLastModifiedTime() == null) {
                next.setVersionDesc("未下载");
            } else if (next.getVersion() == null) {
                next.setVersionDesc("已是最新版本");
            } else if (next.getLastModifiedTime().longValue() < Long.valueOf(Long.parseLong(next.getVersion())).longValue()) {
                next.setVersionDesc("有更新版本");
            } else {
                next.setVersionDesc("已是最新版本");
            }
        }
        Iterator<TreePoint> it2 = this.pointList.iterator();
        while (it2.hasNext()) {
            TreePoint next2 = it2.next();
            if ("0".equals(next2.getISLEAF())) {
                int i4 = 0;
                for (int i5 = 0; i5 < this.pointList.size(); i5++) {
                    if (next2.getID().equals(this.pointList.get(i5).getPARENTID()) && !"已是最新版本".equals(this.pointList.get(i5).getVersionDesc())) {
                        i4++;
                    }
                }
                next2.setNotLoadNumber(i4 + "");
            }
        }
        this.handler.sendEmptyMessage(1);
    }

    @Override // com.gisocn.onemap.view.OfflineDownloadView
    public void getDataFail(String str) {
        hideLoading();
        showToast(str);
    }

    @Override // com.gisocn.onemap.base.BaseFragment, com.gisocn.onemap.base.BaseView
    public void showLoading() {
        showProgressDialog();
        Log.e("showLoading", "showLoading");
    }

    @Override // com.gisocn.onemap.base.BaseFragment, com.gisocn.onemap.base.BaseView
    public void hideLoading() {
        dismissProgressDialog();
        Log.e("hideLoading", "hideLoading");
    }
}
